﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using BLL.A;
using Model.A;

public partial class ActiveProductTrace_ManageActiveProduct_ManageAUnion_AUnionAdd : System.Web.UI.Page
{
    private AUnion au;

    public ActiveProductTrace_ManageActiveProduct_ManageAUnion_AUnionAdd()
    {
        au = new AUnion();
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string packageProductSN = this.TextBox1.Text.Trim();
        string pCBASN = this.TextBox3.Text.Trim();
        string productTypeID = this.TextBox4.Text.Trim();
        AUnionInfo aui = au.LoadEntity(packageProductSN);
        if (!string.IsNullOrEmpty(aui.PackageProductSN))
        {
            string str = "已经关联过的成品序列号，无法再次关联啦！";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
        }
        else
        {
            aui = au.LoadEntity(pCBASN);
            if (!string.IsNullOrEmpty(aui.PackageProductSN))
            {
                string str = "已经关联过的PCBA序列号，无法再次关联啦！";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
            }
            else
            {
                try
                {
                    aui = new AUnionInfo(packageProductSN, pCBASN,productTypeID, DateTime.Now, User.Identity.Name);
                    au.Insert(aui);
                    string str = "关联成功！";
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
                    this.TextBox1.Text = "";
                    this.TextBox3.Text = "";
                    this.TextBox1.Focus();
                }
                catch
                {
                    string str = "出现错误，请联系相关人员！";
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
                }
            }
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string sn = this.TextBox2.Text.Trim();
        AUnionInfo aui = au.LoadEntity(sn);
        IList<AUnionInfo> list = new List<AUnionInfo>();
        list.Add(aui);
        this.DetailsView1.DataSource = list;
        this.DetailsView1.DataBind();
    }
}
